package Apresentation;


import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.faces.view.ViewScoped;

import Domain.Account;
import Domain.Contact_information;
import Domain.Customer;
import Exception.DadosException;
import Integration.Integration;
import Integration.IntegrationImpl;

@ManagedBean
@SessionScoped
public class NovaContaBean {
	
	private Account account;
	private Customer customer;
	private Contact_information contact;
	
	private String repitaSenha;
	
		
	
	public NovaContaBean() {
		super();
		account = new Account();
		customer = new Customer();
		contact = new Contact_information();
		
	}
	
	public String novaConta(){
		
		Integration it = new IntegrationImpl();		
		account.setCustomer(customer);
		account.setContact_information(contact);
		
		try {
			it.insertAccount(account, repitaSenha);
			FacesContext.getCurrentInstance().addMessage("messages", new FacesMessage(FacesMessage.SEVERITY_INFO,"Registration completed successfully",""));
			return "login.xhtml?faces-redirect=true";
		} catch (DadosException e) {			
			e.printStackTrace();
			FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO,e.getMessage(),""));  
			System.out.println(e.getMessage());
			}
		
		return null;
	}
	
	
	

	public Account getAccount() {
		return account;
	}

	public void setAccount(Account account) {
		this.account = account;
	}

	public Customer getCustomer() {
		return customer;
	}

	public void setCustomer(Customer customer) {
		this.customer = customer;
	}

	public Contact_information getContact() {
		return contact;
	}

	public void setContact(Contact_information contact) {
		this.contact = contact;
	}

	public String getRepitaSenha() {
		return repitaSenha;
	}

	public void setRepitaSenha(String repitaSenha) {
		this.repitaSenha = repitaSenha;
	}

	
	
	
	
	
	
	

}
